package com.test.langchain4j.config;

import com.test.langchain4j.service.MySQLMcpService;
import com.test.langchain4j.service.OracleMcpService;
import com.test.langchain4j.service.RedisMcpService;
import dev.langchain4j.model.chat.StreamingChatModel;
import java.util.List;
import java.util.Map;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 2025/8/8 16:09
 * @modifiedBy:
 * @version: 1.0
 */
@Configuration
public class DbMcpConfig {
  @Bean
  public OracleMcpService oracleMcpService(StreamingChatModel streamingChatModel) {
    return AiServiceFactory.getAiService(
        OracleMcpService.class,
        streamingChatModel,
        List.of("cmd", "/c", "E:\\sqlcl\\bin\\sql.exe", "-mcp"),
        Map.of());
  }

  @Bean
  public RedisMcpService redisMcpService(StreamingChatModel streamingChatModel) {
    return AiServiceFactory.getAiService(
        RedisMcpService.class,
        streamingChatModel,
        List.of(
            "cmd",
            "/c",
            "npx",
            "-y",
            "@modelcontextprotocol/server-redis",
            "redis://10.2.54.200:6379/2"),
        Map.of("REDIS_URL", "redis://10.2.38.103:6379"));
  }

  /**
   * "mcpServers": { "mysqldb-mcp-server": { "command": "uvx", "args": [ "mysqldb-mcp-server" ],
   * "env": { "MYSQL_HOST": "localhost", "MYSQL_USER": "root", "MYSQL_PASSWORD": "password",
   * "MYSQL_DATABASE": "[optional]", "MYSQL_READONLY": "true" } } }
   *
   * @param streamingChatModel the streaming chat model
   * @return the my sql mcp service
   */
  @Bean
  public MySQLMcpService mySQLMcpService(StreamingChatModel streamingChatModel) {
    return AiServiceFactory.getAiService(
        MySQLMcpService.class,
        streamingChatModel,
        List.of("cmd", "/c", "uvx", "mysqldb-mcp-server"),
        Map.of(
            "MYSQL_HOST",
            "127.0.0.1",
            "MYSQL_USER",
            "root",
            "MYSQL_PASSWORD",
            "Crscd123@",
            "MYSQL_DATABASE",
            "testdb",
            "MYSQL_READONLY",
            "false"));
  }
}
